<%@ page import="com.NewsService.NewsService" %>
<%@ page import="com.NewsServiceImpl.NewsServiceImpl" %>
<%@ page import="java.util.List" %>
<%@ page import="com.entity.News" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.entity.CountUser" %><%-- Created by IntelliJ IDEA. --%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
  String path =request.getContextPath();
%>
<html>
  <head>
    <title></title>

  </head>
  <body>
<script type="text/javascript">
           function del(id) {
                  //第一步创建安 XMLHttpRequest
                 var ajz  =  new XMLHttpRequest();
                  //第二步：创建一个新的HTTP请求
                 var url="deleAjax?id="+id;
                 ajz.open("GET",url,true);
                  //第三步：发送请求到服务端
                 ajz.send();
                  //第四步：调用回调函数
                 ajz.onreadystatechange=callBack;
                 function callBack() {
                     console.log(ajz)
                     if(ajz.readyState==4 && ajz.status==200){
                         var txt = ajz.responseText;
                         if(txt==1){
                             alert("删除成功");
                             var path=document.getElementById("path").value;
                             window.location.href=path+"/index.jsp"
                         }else {
                             alert("删除失败")
                         }
                     }
                 } //第一步创建安 XMLHttpRequest
                 var ajz  =  new XMLHttpRequest();
                  //第二步：创建一个新的HTTP请求
                 var url="deleAjax?id="+id;
                 ajz.open("GET",url,true);
                  //第三步：发送请求到服务端
                 ajz.send();
                  //第四步：调用回调函数
                 ajz.onreadystatechange=callBack;
                 function callBack() {
                     console.log(ajz)
                     if(ajz.readyState==4 && ajz.status==200){
                         var txt = ajz.responseText;
                         if(txt==1){
                             alert("删除成功");
                             var path=document.getElementById("path").value;
                             window.location.href=path+"/index.jsp"
                         }else {
                             alert("删除失败")
                         }
                     }
                 }
           }
</script>




  <h1>当前在线人数是：<%=CountUser.Count%></h1>
    <%
      NewsService newsService = new NewsServiceImpl();

      //List<News> newsList= newsService.ServiceSelectAll();
        //初始化分页参数
         int index=0;
         int crenCount=1;
         List<News> newsList= (List<News>) session.getAttribute("list");
         Object  index1= session.getAttribute("index1");

         if (index1==null){
             index=1;
         }else {
             index= (int) session.getAttribute("index1");
         }

        if(newsList ==null){
            newsList=newsService.ServiceSelectAll();

        }

   %>
    <div>
      <table style="border-color: red;border:1px solid;">
    <%
      for (int i=0;i<newsList.size();i++) {
    %>
        <tr>
           <td>
             <%=newsList.get(i).getId()%>
           </td>
          <td>
            <%=newsList.get(i).getCategoryId()%>
          </td>
          <td>
            <%=newsList.get(i).getTitle()%>
          </td>
          <td>
            <%=newsList.get(i).getSummary()%>
        </td>
            <td>
                <%=newsList.get(i).getContent()%>
            </td>
            <td>

                <img src="<%=newsList.get(i).getPicPath()%>"/>
            </td>
            <td><a href="<%=path%>/deleteNews?newsid=<%=newsList.get(i).getId()%>&&name='你好'">删除</a></td>
            <td><a href="#" onclick="del(<%=newsList.get(i).getId()%>)">删除</a></td>
            <td><a href="<%=path%>/updateNews?newsid=<%=newsList.get(i).getId()%>">修改</a></td>
            <td><a href="#">添加</a></td>
            <div id="ddd"></div>
            <input type="hidden" id="path" value="<%=path%>">
        </tr>

    <%
      }
    %>
       <tr>
           <td><a href="pageManage.jsp?index=<%=(index-1)<0 ? 0:index-1%>&crenCount=<%=crenCount%>">上一下</a></td>
           <td><a href="pageManage.jsp?index=<%=index+1%>&crenCount=<%=crenCount%>">下一页</a></td>

       </tr>
      </table>
    </div>
  </body>
</html>